<template>
	<view>
		<u-navbar :border-bottom="false" title="修改密码" title-color="#fff" back-icon-color="#fff">
			<template v-slot:right>
				<text @click="submit" class="nav-bar__cancel">提交</text>
			</template>
		</u-navbar>
		<view class="pickCon">
			<view class="pick-time">
				<text class="label">原密码</text>
				<input type="password" placeholder-class="inputplace" v-model="oldpwd" placeholder="输入原密码" />
			</view>
			<view class="pick-time">
				<text class="label">新密码</text>
				<input type="password" placeholder-class="inputplace" v-model="newpwd" placeholder="输入新密码" />
			</view>
			<view class="pick-time">
				<text class="label">确认密码</text>
				<input type="password" placeholder-class="inputplace" v-model="newpwd2" placeholder="请再次输入新密码" />
			</view>
			
		</view>
		
	</view>
</template>

<script>
export default {
	data() {
		return {
			oldpwd:'',//原密码
			newpwd:'',//新密码
			newpwd2:'',//再次密码
			errorList:'',//错误内容
		};
	},
	methods: {
		// 验证
		validate(){
			this.errorList = ''
			if (this.oldpwd == ''||this.newpwd == ''||this.newpwd2 == '') {
			    this.errorList='密码不可为空';
			} else {
				// 长度验证暂隐
			  // if (this.newpwd.length < 8) {
			  //   this.errorList='密码长度不得少于8位';
			  // }else 
				if(this.oldpwd==this.newpwd){
					this.errorList='新旧密码不能相同!';
					return
				}
				if(this.newpwd2!=this.newpwd){
					this.errorList='两次输入新密码不一致';
				}
			}
		},
		// 提交
		submit() {
			this.validate()
			if(this.errorList){
				uni.showToast({
					icon: 'none',
					title: this.errorList
				});
				return
			}
			const data={
				"newPwd": this.newpwd.toString(),
				"oriPwd": this.oldpwd.toString()
			}
			// 接口更改密码
			return new Promise((resolve, reject) => {
				this.request
					.post('/app/teacher/mine/updatePassword', data)
					.then(res => {
						uni.showToast({
								icon: 'none',
								title: '修改成功'
							});
							//清除本地
							uni.setStorage({
								key: 'user',
								data: null
							})
					setTimeout(function(){
						uni.redirectTo({
							url: '/pages/login/login'
						});
					},1000)
						resolve()
					});
			});
		}
	}
};
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style scoped lang="scss">
.nav-bar__cancel {
	font-size: 30upx;
	font-weight: 400;
	color: #ffffff;
	margin-right: 30upx;
}
.pick-time {
	height: 110upx;
	display: flex;
	align-items: center;
	font-size: 32upx;
	font-weight: 400;
	color: #363940;
	border-bottom: 1upx solid #EBEBEB;
	text {
		width: 173upx;
	}
	picker {
		flex: 1;
	}
}
.pick-time:last-child{
	border-bottom: none;
}
 .inputplace{ 
       color: #A9ABB0;
}
.pickCon{
	margin-top: 20upx;
	padding: 0 30upx;
	background: #fff;
}
</style>
